package com.cat.dataStructure03;

import java.util.Arrays;

/**
 *   @description https://leetcode.cn/problems/determine-if-two-strings-are-close/
 *   @author 曲大人的喵
 *   @create 2025/11/15 10:08
 *   @since JDK17
 */

public class Solution56 {
    public boolean closeStrings(String word1, String word2) {
        int n = word1.length(), m = word2.length();
        if (n != m) {
            return false;
        }
        int[]cnt1 = new int[26], cnt2 = new int[26];
        for (var x : word1.toCharArray()) {
            cnt1[x - 'a']++;
        }
        for (var x : word2.toCharArray()) {
            cnt2[x - 'a']++;
        }
        for (int i = 0; i < 26; i++) {
            if ((cnt1[i] != 0) != (cnt2[i] != 0)) {
                return false;
            }
        }

        Arrays.sort(cnt1);
        Arrays.sort(cnt2);
        for (int i = 0; i < 26; i++) {
            if (cnt1[i] != cnt2[i]) {
                return false;
            }
        }



        return true;
    }
}
